package day06;

import java.util.Arrays;

public class EmployeeBiz {
    public void addEmp(Employee boss,Employee e){
        if(null == boss.getEmps()){
            System.out.println("sorry...");
            return;
        }

        Employee[] arr = Arrays.copyOf(boss.getEmps(),boss.getEmps().length+1);
        arr[arr.length-1] = e;
        boss.setEmps(arr);
    }

    public void findAll(Employee boss){
        if(null == boss.getEmps()){
            System.out.println("sorry...");
            return;
        }
        for (Employee emp : boss.getEmps()){
            System.out.println("\t"+emp);
        }
    }

    public void delById(Employee boss,int id){
        if(null == boss.getEmps()){
            System.out.println("sorry...");
            return;
        }
        Employee[] emps = boss.getEmps();
        Employee[] arr = new Employee[emps.length-1];
        int pos = 0;
        for (Employee emp : emps){
            if(emp.getId() != id){
                arr[pos++] = emp;
            }
        }
        boss.setEmps(arr);
    }
}
